home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Comms & Internet / LinkConverter 1.1.2 / Dialog Director v0.7 / Examples / EditFontSpec.as < prev    next >
Encoding:
Text File  |  1998-02-01  |  3.4 KB  |  88 lines  |  [TEXT/ToyS]

  1. property fontDlog : {bounds:null, contents:[¬
  2.     {class:push button, bounds:[190, 200, 250, 220], name:"OK"}, ¬
  3.     {class:push button, bounds:[110, 200, 170, 220], name:"Cancel"}, ¬
  4.     {class:pop up, name:"Font:", bounds:[7, 8, 250, 28], contents:"FONT"}, ¬
  5.     {class:pop up, bounds:[96, 35, 96, 55], contents:"9;10;12;14;18;24;36;48", text field:5}, ¬
  6.     {class:text field, bounds:[50, 37, 90, 53], name:"Size:", name bounds:[10, 37, 48, 53]}, ¬
  7.     {class:check box, name:"Plain", bounds:[60, 60, 150, 76]}, ¬
  8.     {class:check box, name:"Bold", bounds:[60, 76, 150, 92], enabled:-6}, ¬
  9.     {class:check box, name:"Italic", bounds:[60, 92, 150, 108], enabled:-6}, ¬
  10.     {class:check box, name:"Underline", bounds:[60, 108, 150, 124], enabled:-6}, ¬
  11.     {class:check box, name:"Outline", bounds:[60, 124, 150, 140], enabled:-6}, ¬
  12.     {class:check box, name:"Shadow", bounds:[60, 140, 150, 156], enabled:-6}, ¬
  13.     {class:check box, name:"Condensed", bounds:[60, 156, 150, 172], enabled:-6}, ¬
  14.     {class:check box, name:"Extended", bounds:[60, 172, 150, 188], enabled:-6}, ¬
  15.     {class:static text, bounds:[10, 60, 50, 76], contents:"Style:"} ¬
  16.         ], style:movable dialog, name:"Edit Font"}
  17.  
  18. on EditFontSpec(fs)
  19.     set s to fs's style
  20.     if s's class = integer then
  21.         set R to [fs's name, 1, fs's size, s = 0, s mod 2 = 1]
  22.         repeat 6 times
  23.             set s to s div 2
  24.             set R to R & (s mod 2 = 1)
  25.         end repeat
  26.     else
  27.         set s to s as list
  28.         set R to [fs's name, 1, fs's size, s = [] or s contains plain, s contains bold, ¬
  29.             s contains italic, s contains underline, s contains outline, ¬
  30.             s contains shadow, s contains condensed, s contains expanded]
  31.     end if
  32.     if fontDlog's bounds = null then set fontDlog's bounds to dd calc dialog bounds [260, 230]
  33.     dd set value of items 3 thru 13 of (dd make dialog fontDlog) to R
  34.     repeat
  35.         set i to dd interact with user
  36.         if i = 1 then
  37.             try
  38.                 set siz to (dd get value of item 5 of dialog 1) as integer
  39.                 if siz < 4 or siz > 127 then error
  40.                 exit repeat
  41.             on error
  42.                 beep 1
  43.                 Alert(1, "Invalid font size!", ¬
  44.                     "The font size must be an integer between 4 and 127.", "OK", "")
  45.                 dd set selection of item 5 of dialog 1 to [0, -1]
  46.             end try
  47.         else if i = 2 then
  48.             exit repeat
  49.         end if
  50.     end repeat
  51.     set f to dd get value of every item of dialog 1
  52.     dd delete dialog 1
  53.     set bounds of fontDlog to last item of f
  54.     tell f
  55.         if item 2 then return fs
  56.         set s to []
  57.         if not item 6 then
  58.             if item 7 then set s to [bold]
  59.             if item 8 then set s to s & italic
  60.             if item 9 then set s to s & underline
  61.             if item 10 then set s to s & outline
  62.             if item 11 then set s to s & shadow
  63.             if item 12 then set s to s & condensed
  64.             if item 13 then set s to s & expanded
  65.         end if
  66.         if s = [] then
  67.             set s to plain
  68.         else if s's length = 1 then
  69.             set s to s's item 1
  70.         end if
  71.         return {name:item 3, size:siz, style:s}
  72.     end tell
  73. end EditFontSpec
  74.  
  75. on Alert(icn, msg1, msg2, btn1, btn2)
  76.     set c to [{class:push button, bounds:[295, 83, 353, 103], name:btn1}]
  77.     if btn2 ≠ "" then set c to c & [{class:push button, bounds:[225, 83, 283, 103], name:btn2}]
  78.     (dd auto dialog {size:[362, 112], style:movable dialog, contents:c & [¬
  79.         {class:icon, bounds:[17, 9, 17 + 32, 9 + 32], contents:icn}, ¬
  80.         {class:static text, bounds:[67, 9, 352, 9 + 32], contents:msg1}, ¬
  81.         {class:static text, bounds:[67, 45, 352, 45 + 26], contents:msg2, font:5} ¬
  82.             ]})'s item 1
  83. end Alert
  84.  
  85. dd install with fonts [null, null, null, null, {name:"Geneva", size:10}] with grayscale
  86. set fs to EditFontSpec({name:"Times", size:64, style:bold})
  87. dd uninstall
  88. return fs